package com.xm.uti;

import com.google.gson.Gson;

/**
 * 返回数据的工具类---统一结果的格式
 * @author
 *
 */
public class Result {
	private int code;  //状�?�码，是客户端判断成功失败的依据�?0成功，其他失�?
	private String msg; //描述，失败的原因
	private Object data; //数据
	private int count; //条数，layui需要的格式
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	/**
	 * 返回状态码，描述，数据
	 * @param code
	 * @param msg
	 * @param data
	 * @return
	 */
	public static String toClient(int code,String msg,Object data) {
		Result r = new Result();
		r.setCode(code);
		r.setMsg(msg);
		r.setData(data);
		Gson t = new Gson();
		String json = t.toJson(r);
		return json;
	}
	
	/**
	 * 返回状态码，描述
	 * @param code
	 * @param msg
	 * @param data
	 * @return
	 */
	public static String toClient(int code,String msg) {
		Result r = new Result();
		r.setCode(code);
		r.setMsg(msg);
		Gson t = new Gson();
		String json = t.toJson(r);
		return json;
	}
	
	/**
	 * 返回状态码，描述，数据，条数(总条数)
	 * （layui需要）
	 * @param code
	 * @param msg
	 * @param data
	 * @param count
	 * @return
	 */
	public static String toClient(int code,String msg,Object data,int count) {
		Result r = new Result();
		r.setCode(code);
		r.setMsg(msg);
		r.setData(data);
		r.setCount(count);
		Gson t = new Gson();
		String json = t.toJson(r);
		return json;
	}
}
